﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using FortuneHeaven.DAL.Base;
using FortuneHeaven.Entity.Accounts;

namespace FortuneHeaven.DAL.Accounts
{
    public class AccountsDAL : GameUserBaseDAL
    {
        public AccountsInfo GetInfo(object id)
        {
            string sql = "select * from AccountsInfo where UserID=@p0";
            List<AccountsInfo> list = dbOper.Query<AccountsInfo>(sql, id);
            if (list.Count > 0)
            {
                return list.First();
            }
            else
            {
                return null;
            }


        }

        public AccountsInfo GetInfobyAccount(string accountName)
        {
            string sql = "select * from AccountsInfo where Accounts=@p0";
            List<AccountsInfo> list = dbOper.Query<AccountsInfo>(sql, accountName);
            if (list.Count > 0)
            {
                return list.First();
            }
            else
            {
                return null;
            }
        }

        public int GetRegisterCount(int netBarID)
        {
            string sql = "select count(*) from AccountsInfo where NetBarID=@p0";
            int count = dbOper.GetScalar<int>(sql, netBarID);
            return count;
        }

        public int GetTodayRegisterCount(int netBarID,DateTime date)
        {
            string sql = "select count(*) from AccountsInfo where NetBarID=@p0 and RegisterDate between '" + date.Date + "' and '" + date.Date.AddDays(1) + "'";
            int count = dbOper.GetScalar<int>(sql, netBarID);
            return count;
        }

        public long GetTotalScore(int netBarID)
        {
            string sql = "select isnull(sum(score),0) from QPTreasureDB.dbo.GameScoreInfo where userid in (select userid from accountsinfo where NetBarID = @p0)";
            long count = dbOper.GetScalar<long>(sql, netBarID);
            return count;
        }

        public int GetMemberCount(int netBarID)
        {
            string sql = "select count(*) from AccountsInfo where NetBarID=@p0 and MemberOrder>0";
            int count = dbOper.GetScalar<int>(sql, netBarID);
            return count;
        }
    }

}
